package project.euler.honk.problem.to50;

public final class Problem23 {

	private static final int SIZE = 28123;
	private static final int[] abNumbers = new int[SIZE];
	private static final boolean[] check = new boolean[SIZE + SIZE];

	private static boolean isAbundant(int number) {
		int sum = 0;
		for (int i = 1; i * i <= number; i++) {
			if (number % i == 0) {
				sum += i;
				if (i != 1 && i != number / i)
					sum += number / i;
				if (sum > number)
					return true;
			}
		}
		return sum > number;
	}
	
	public static int solve() {
		int c = 0;
		for (int i = 12; i < SIZE; i++) {
			if (isAbundant(i))
				abNumbers[c++] = i;
		}

		for (int i = 0; i < c - 1; i++) {
			for (int j = 0; j < c - 1; j++) {
				check[abNumbers[i] + abNumbers[j]] = true;
			}
		}
		int sum = 0;
		for (int i = 0; i < SIZE; i++)
			if (!check[i])
				sum += i;
		return sum;
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		int result = solve();
		long end = System.currentTimeMillis();
		System.out.println("Result: " + result + " Time: " + (end - start));
	}

}
